<?php
function SVC_FUNC_LOGIN($request)
{
    if(($dbconn=worker::get_dbconn('DB1')) == false)
        return false;

    if(!isset($request['loginname']) ||
            strlen($request['loginname']) > misc::NAME_SIZE)
    {
        $response=array('errcode'=>SOAR_ERR::PARA);
        return $response;
    }
    $loginname=$request['loginname'];

//    try
//    {
//        $stmt=$dbconn->prepare("update memb_info set ".
//                "update_ts=sysdate(),login_times=login_times+1 ".
//                "where loginname=:loginname");
//        $stmt->execute(array(':loginname'=>$loginname));
//        if($stmt->rowCount() == 0)
//            $response=array('errcode'=>'MEMB_NOT_FOUND');
//        else
//            $response=array('errcode'=>SOAR_ERR::OK);
//    }
//    catch(PDOException $e)
//    {
//        errlog::add("%s: worker(%d) update memb_info fail: %s",
//                __METHOD__, worker::$worker_idx,
//                $e->getMessage()); 
//        return false;
//    }

    $stmt=$dbconn->prepare("update memb_info set ".
            "update_ts=sysdate(),login_times=login_times+1 ".
            "where loginname=?");
    if($stmt === false)
    {
        errlog::add("%s: worker(%d) prepare update memb_info fail: %d %s",
                __METHOD__, worker::$worker_idx,
                $dbconn->errno, $dbconn->error);
        return false;
    }
    $stmt->bind_param('s', $loginname);
    if($stmt->execute() == false)
    {
        errlog::add("%s: worker(%d) update memb_info fail: %d %s",
                __METHOD__, worker::$worker_idx,
                $stmt->errno, $stmt->error);
        return false;
    }
    if($stmt->affected_rows == 0)
    {
        $response=array('errcode'=>'MEMB_NOT_FOUND');
    }
    else
    {
        $response=array('errcode'=>SOAR_ERR::OK);
    }
    $stmt->close();

    return $response;
}
?>
